﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.BusinessObjects;
using Provausio.Common.Utility.Extensions;

namespace TrainingManagement.api.Models.Data.Readers
{
    public class SkillDataReader : BusinessOperation<IDataRecord, Skill>
    {
        public override Skill Run(IDataRecord input)
        {
            var skill = new Skill
            {
                Title = input["Title"].ToString(),
                DocId = input["DocID"].DbTo<int?>(),
                SkillId = input["SkillID"].DbTo<int>()
            };

            //currently only shows up when building skillsets (Skill_SkillSet)
            if (input.HasColumn("RetrainFrequency"))
            {
                skill.RetrainFreq = input["RetrainFrequency"].DbTo<int>();
            }

            return skill;
        }
    }
}